<?php

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;

class memberoauthModel extends Model
{
    protected $table = 'member_oauth';
    protected $primaryKey = 'id';
    protected $appends = [];

    public $timestamps = false;

    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function member()
    {
        return $this->belongsTo(\memberModel::class, 'member_id', 'id');
    }

    public function getPlatformTextAttribute()
    {
        // H5=H5,wxOfficialAccount=微信公众号,wxMiniProgram=微信小程序,App=App
        switch ($this->attributes['platform']) {
            case 'H5':
            case 'App':
                return $this->attributes['platform'];
            case 'wxOfficialAccount':
                return '微信公众号';
            case 'wxMiniProgram':
                return '微信小程序';
        }
    }

    public function getLogintimeTextAttribute()
    {
        $text = '';
        if(!empty($this->attributes['logintime'])){
            $text = timestamp($this->attributes['logintime']);
        }

        return $text;
    }
}
